﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
	<Style x:Key="ComboBoxBuildStyle" TargetType="{x:Type ComboBox}">
		<Setter Property="SnapsToDevicePixels" Value="true"/>
		<Setter Property="Template" Value="{DynamicResource ComboBoxBuildControlTemplate}"/>
		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
		<Setter Property="ItemContainerStyle" Value="{DynamicResource ComboBoxItemStyle}"/>
	</Style>
	<ControlTemplate x:Key="ComboBoxBuildControlTemplate" TargetType="{x:Type ComboBox}">
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="0.74*"/>
				<ColumnDefinition Width="0.26*"/>
			</Grid.ColumnDefinitions>
			<!-- The ToggleButton is databound to the ComboBox itself to toggle IsDropDownOpen -->
			<ToggleButton Grid.Column="0" Template="{DynamicResource ToggleButtonControlTemplate}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" Grid.ColumnSpan="2" d:LayoutOverrides="GridBox"/>
			<ContentPresenter HorizontalAlignment="Left" Margin="3,3,0,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>
			<TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="{TemplateBinding Tag}" TextWrapping="Wrap" x:Name="TextBlockNumberOfBuilds" Margin="0,3,25,3" Grid.Column="1"/>
						
			<!-- The TextBox must be named PART_EditableTextBox or ComboBox will not recognize it -->
			<TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,0,0,0" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>
						
			<!-- The Popup shows the list of items in the ComboBox. IsOpen is databound to IsDropDownOpen which is toggled via the ComboBoxToggleButton -->
			<Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide" Grid.ColumnSpan="2">
				<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
					<Border x:Name="DropDownBorder" Background="{DynamicResource BrushControlBackgroundLight}" BorderBrush="{DynamicResource ImpassiveColor4}" BorderThickness="1" CornerRadius="0,0,3,3"/>
					<ScrollViewer Margin="4,6,4,6" Style="{DynamicResource ComboBoxScrollViewerStyle}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
							
						<!-- The StackPanel is used to display the children by setting IsItemsHost to be True -->
						<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/>
								
					</ScrollViewer>
				</Grid>
			</Popup>
		</Grid>
		<ControlTemplate.Triggers>						
			<!-- This forces the DropDown to have a minimum size if it is empty -->
			<Trigger Property="HasItems" Value="false">
				<Setter Property="MinHeight" Value="95" TargetName="DropDownBorder"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
			</Trigger>
			<Trigger Property="IsGrouping" Value="true">
				<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
			</Trigger>
			<Trigger Property="AllowsTransparency" SourceName="Popup" Value="true">
				<Setter Property="CornerRadius" Value="4" TargetName="DropDownBorder"/>
				<Setter Property="Margin" Value="0,2,0,0" TargetName="DropDownBorder"/>
			</Trigger>
			<Trigger Property="IsEditable" Value="true">
				<Setter Property="IsTabStop" Value="false"/>
				<Setter Property="Visibility" Value="Visible" TargetName="PART_EditableTextBox"/>
				<Setter Property="Visibility" Value="Hidden" TargetName="ContentSite"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	<!-- Resource dictionary entries should be defined here. -->
</ResourceDictionary>